#include "stdafx.h"
#include "VS2010CtxMenuFixHook.h"

static HHOOK g_hHook = NULL;

LRESULT WINAPI KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
    if (nCode < 0)
    {
        return CallNextHookEx(NULL, nCode, wParam, lParam);
    }

    if (wParam == VK_APPS)
    {
        if (g_bIsVsProcess)
        {
            POINT pt;
            GetCursorPos(&pt);
            SetCursorPos(pt.x, 1);
        }
    }

    return CallNextHookEx(NULL, nCode, wParam, lParam);
}

VS2010CTXMENUFIXHOOK_API BOOL SetHook(void)
{
    if (g_hHook == NULL)
    {
        g_hHook = SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProc, g_hModule, 0);

        if (g_hHook == NULL)
        {
            return FALSE;
        }
    }

    return TRUE;
}

VS2010CTXMENUFIXHOOK_API BOOL RemoveHook(void)
{
    if (g_hHook != NULL)
    {
        UnhookWindowsHookEx(g_hHook);
        g_hHook = NULL;
    }

    return TRUE;
}
